<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>类继承</title>
    <script>
      class Car {
        constructor(brand) {
          this.brand = brand;
        }
        show() {
          console.log(`汽车品牌为：${this.brand}`);
        }
      }
      class Lexus extends Car {
        constructor(brand, model) {
          super(brand);
          this.model = model;
        }
        getPrice() {
          switch (this.model) {
            case "RX":
              return 60;
            case "UX":
              return 40;
            default:
              throw new Error("未知车型");
          }
        }
      }
      let mycar = new Lexus("Lexus", "RX");
      mycar.show();
      console.log("价格为：", mycar.getPrice(), "万");
    </script>
  </head>
  <body></body>
</html>
